package com 
{
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.XMLLoader;
	import com.managers.XmlManager;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Matthew Ladouceur
	 */
	public class TheSkillList extends FlaObject
	{
		private var _skills:Array = new Array();
		
		private var _mask:Sprite = new Sprite();
		private var _content:Sprite = new Sprite();
		private var _scrollBar:ScrollBarLite;
		
		private var _scrollFace:Sprite = new Sprite();
		private var _scrollTrack:Sprite = new Sprite();
		
		public var chosenCost:Number = 0;
		
		public function TheSkillList() 
		{
			//_content.graphics.beginFill(0xeeeeeee);
			//_content.graphics.drawRoundRect(0, 0, 300, 2000, 10, 10);
			//_content.graphics.endFill();
			addChild(_content);
			
			_mask.graphics.beginFill(0x000000);
			_mask.graphics.drawRoundRect(0, 0, 300, 400, 10, 10);
			_mask.graphics.endFill();
			addChild(_mask);
			_content.mask = _mask;
			
			_scrollFace.graphics.beginFill(0xff0000);
			_scrollFace.graphics.drawRoundRect(0, 0, 16, 64, 5, 5);
			_scrollFace.graphics.endFill();
			_scrollFace.x = 300;
			
			_scrollTrack.graphics.beginFill(0x0000ff);
			_scrollTrack.graphics.drawRoundRect(0, 0, 16, 400, 5, 5);
			_scrollTrack.graphics.endFill();
			_scrollTrack.x = 300;
			
			addChild(_scrollTrack);
			addChild(_scrollFace);			
			
			var xml:XMLList = XmlManager.instance.getXML("skills");
			for (var i:int = 0; i < xml.skill.length(); i++) {
				_skills.push(new Skill(xml.skill[i]));
				_skills[i].y = i * 30;
				_skills[i].width = 400;
				_skills[i].addEventListener(MouseEvent.CLICK, onClick);
				_content.addChild(_skills[i]);
			}
			
			_scrollBar = new ScrollBarLite(_scrollFace, _scrollFace, _scrollFace, _content, _mask, _scrollTrack);
			_scrollBar.registerMouseWheelTarget(this);
			_scrollBar.registerCustomContentScroll(_onScroll);
			_scrollBar.onContentSizeChange();
		}
		
		public function update(string:String):void {
			for (var i:int = 0; i < _skills.length; i++) {
				_skills[i].updateCost(string);
			}
		}
		
		private function onClick(e:MouseEvent):void {
			dispatchEvent(e);
		}

		private function _onScroll(newY:Number):void{
			var len:uint;
			_content.y = newY;
		} 
		
	}

}